import pymongo


def getClient():
    myClient = pymongo.MongoClient("mongodb://localhost:27017/")
    return myClient


def save(client):
    myDb = client["w3cschooldb"]
    myCol = myDb["sites"]
    myDict = {"name": "w3cschool", "alexa": "10000", "url": "https://www.w3cschool.cn"}
    x = myCol.insert_one(myDict)
    print(x)
    mylist = [
        {"name": "Taobao", "alexa": "100", "url": "https://www.taobao.com"},
        {"name": "QQ", "alexa": "101", "url": "https://www.qq.com"},
        {"name": "Facebook", "alexa": "10", "url": "https://www.facebook.com"},
        {"name": "知乎", "alexa": "103", "url": "https://www.zhihu.com"},
        {"name": "Github", "alexa": "109", "url": "https://www.github.com"}
    ]
    x = myCol.insert_many(mylist)
    print(x.inserted_ids)


if __name__ == "__main__":
    client = getClient()
    save(client)
